package com.video.netty.send;

import com.video.commons.sendaop.ISocketSend;
import com.video.entity.Webcon;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 新增或者修改分控信息
 *
 * {"id":"updateWebconUser", "account":"admin", "password":"123456","users":["1", "2", "3"]}
 *
 */
@Component
public class UpdateWebconUserSend extends ISocketSend {

    @Override
    public Map<String, Object> sendMsg(Object... objs) {

        //获得新增或者修改的分控对象
        Webcon webcon = (Webcon) objs[0];

        Map<String, Object> map = new HashMap<>();
        map.put("id", "updateWebconUser");
        map.put("account", webcon.getAccount());
        map.put("password", webcon.getPassword());

        List<String> users = new ArrayList<>();
        String clients = webcon.getClients();
        String[] split = clients.split("\\|");
        for (int i = 0; i < split.length; i++) {
            users.add(split[i].split("-")[1]);
        }
        map.put("users", users);
        return map;
    }
}
